package com.szjlc.blog.controller;


import com.szjlc.blog.common.result.WebServiceResponse;
import com.szjlc.blog.common.utils.TraceIdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制层
 * @author steve
 * @since 2022-11-13
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping(value = "/traceId")
    public WebServiceResponse<String> testTraceId() {
        if (StringUtils.hasText(TraceIdUtil.getTraceId())) {
            log.info("traceId={}", TraceIdUtil.getTraceId());
            return WebServiceResponse.success(TraceIdUtil.getTraceId());
        }
        else {
            String generateTraceId = TraceIdUtil.generateTraceId();
            log.info("generateTraceId={}", generateTraceId);
            return WebServiceResponse.success(generateTraceId);
        }
    }
}
